class Solution:
    def addBinary(self, a: str, b: str) -> str:
        i, j = len(a) - 1, len(b) - 1
        carry = 0
        res = ''
        while (i >= 0 or j >= 0):
            digita = ord(a[i]) - ord('0') if i >= 0 else 0
            digitb = ord(b[j]) - ord('0') if j >= 0 else 0
            i -= 1
            j -= 1

            sum = digita + digitb + carry
            carry = 1 if sum >= 2 else 0

            sum = sum - 2 if sum >= 2 else sum
            res += str(sum)

        if carry == 1:
            res += "1"
        return res[::-1]



if __name__ == '__main__':
    s = Solution()
    a = "1001"
    b = "10"
    ans = s.addBinary(a, b)
    print(ans)